//
//  TreasureMap.swift
//  Facade
//
//  Created by LY on 2017/11/1.
//  Copyright © 2017年 DesignPatterns. All rights reserved.
//

import Foundation

class TreasureMap {
    enum Treasures {
        case GALLEON,BURIED_GOLD,SUNKEN_JEWELS
    }
    struct MapLocation {
        let gridLetter : Character
        let gridNumber : UInt
    }
    func findTreasure(type:Treasures) -> MapLocation{
        switch type {
        case .GALLEON:
            return MapLocation(gridLetter: "D", gridNumber: 6)
        case .BURIED_GOLD:
            return MapLocation(gridLetter: "C", gridNumber: 2)
        case .SUNKEN_JEWELS:
            return MapLocation(gridLetter: "F", gridNumber: 12)
        }
    }
}

class PirateShip{
    struct ShipLocation {
        let NorthSouth : Int
        let EastWest : Int
    }
    var currentPosition : ShipLocation
    var movementQueue = DispatchQueue(label: "shipQ")
    init() {
        currentPosition = ShipLocation(NorthSouth: 5, EastWest: 5)
    }
    func moveToLocation(location:ShipLocation,callback:@escaping(ShipLocation) -> Void){
        movementQueue.async {
            self.currentPosition = location;
            callback(self.currentPosition)
        }
    }
}

class PirateCrew{
    let workQueue = DispatchQueue(label: "crewQueue")
    enum Actions {
        case ATTACK_SHIP,DIG_FOR_GLOD,DIVE_FOR_JEWELS
    }
    func preformAction(action:Actions,callback:@escaping(Int) -> Void){
        var prizeValue = 0
        switch action {
        case .ATTACK_SHIP:
            prizeValue = 10000
        case .DIG_FOR_GLOD:
            prizeValue = 5000
        case .DIVE_FOR_JEWELS:
            prizeValue = 1000
        }
        callback(prizeValue)
    }
}
